home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mc51bugs / q32654 < prev    next >
Text File  |  1988-07-20  |  1KB  |  45 lines

  1. Q32654 Incorrect Code for Loop with Initializer i=j=constant
  2. C Compiler
  3. 5.10   | 5.10
  4. MS-DOS | OS/2
  5.  
  6. Summary:
  7.    The code generated for the following "for loop" is incorrect. The
  8. variable "i" is set up in the DI register and is loaded with the value
  9. 10 before the loop begins. This process causes all of the printed
  10. answers to be off by 10.
  11.    Microsoft has confirmed this to be a problem in Version 5.10 of the
  12. C compiler. We are researching this problem and will post new
  13. information as it becomes available.
  14.    The problem is related to the initialization portion of the "for
  15. loop;" i.e., the statement i=j=0.
  16.    You can work around this problem by initializing one of the
  17. variables outside of the "for loop."
  18.  
  19. More Information:
  20.  
  21. int array[10]={1,2,3,4,5,6,7,8,9,10};
  22. main()
  23. {
  24.  
  25.  
  26.  int i,j,k;
  27.  
  28.  k=0;
  29.        /* work around by initializing i or j outside of loop: */
  30.        /* i = 0 */
  31.         for (i=j=0;j<10;j++)
  32.         {
  33.                 if (array[j]==5) k=i;
  34.  
  35.                 i++;
  36.         }
  37.  printf("\r\ni=%d j=%d k=%d",i,j,k);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. Keywords:  buglist5.10
  44. Updated  88/07/21 03:19
  45.